<template>
    <el-image
        :style="{ width: width, height: height }"
        :src="src"
        :fit="fit"
        :preview-src-list="urlList"
        :initial-index="initialIndex"
        :hide-on-click-modal="hidemodal"
        :z-index="Zindex">
        <template #error>
            <div class="image-slot">
                <el-icon size="30" color="#666666">
                    <Picture />
                </el-icon>
            </div>
        </template>
    </el-image>
</template>

<script lang="ts" setup>
const props = defineProps({
    width: {
        // 图片宽度
        type: String,
        default: '100px',
    },
    height: {
        // 图片高度
        type: String,
        default: '100px',
    },
    src: {
        // 图片url
        type: String,
        required: true,
    },
    fit: {
        // 确定图片如何适应容器框，同原生 object-fit
        type: String,
        default: 'cover',
    },
    urlList: {
        // 开启图片预览功能
        type: Array,
        default: () => {
            return [];
        },
    },
    initialIndex: {
        // 初始预览图像索引，小于 url-list 的长度
        type: Number,
        default: 0,
    },
    hidemodal: {
        // 开启图片预览功能
        type: Boolean,
        default: false,
    },

    Zindex: {
        // 浏览器加载图像的策略，和 浏览器原生能力一致
        type: Number,
        default: 9999,
    },
});
</script>

<style lang="scss" scoped>
.image-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background: var(--el-fill-color-light);
    color: var(--el-text-color-secondary);
    font-size: 30px;
}
</style>
